package com.unipay.system.service.impl;

import com.unipay.model.system.SysUser;
import com.unipay.system.custom.CustomUser;
import com.unipay.system.service.SysUserService;
//import com.unipay.system.service.UserDetailsService;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Collections;

/**
 * @BelongsProject: unipay-auth-parent
 * @Author: cmy
 * @CreateTime: 2023-02-14  19:20
 * @Description: TODO
 */
@Component
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public CustomUser loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = sysUserService.getInfoByUsername(username);
        if (null == sysUser){
            throw new UsernameNotFoundException("用户名不存在！！！");
        }
        if (sysUser.getStatus().intValue() == 0){
            throw new RuntimeException("账号已停用！");
        }
        return new CustomUser(sysUser, Collections.emptyList());
    }
}
